import json

import requests


class FP():
    def __init__(self):
        self.fp_host = "http://192.168.1.160:11180"
        self.cookie = "yt_cluster_id=OK_1545115071; userMessage=%7B%22username%22%3A%22admin%22%2C%22password%22%3A%22admin12345678%22%2C%22isRemembered%22%3Atrue%7D; session_id=461890812@OK_1545115071"

    def get_feature(self, pic_base64):
        _url = self.fp_host + "/face/v1/framework/face_image/repository/picture/extract"
        headers = {
            "Content-Type": "application/json",
            "Cookie": self.cookie
        }
        payload = {
            "image_content_base64": str(pic_base64),
            "options": {
                "face_image_type": 0,
                "max_face_allowed": 2
            }
        }
        response = requests.request("POST", _url, headers=headers, data=json.dumps(payload))
        if response.ok:
            rsp = response.json()
            if rsp.get("message") == "OK":
                if len(rsp.get("results"))<1:
                    return False
                else:
                    return rsp.get("results")[0].get("feature_base64")
            else:
                return False
        else:
            return False

    def get_ovo_result(self, feature1, feature2):
        _url = self.fp_host + "/face/v1/framework/face/verify"
        headers = {
            "Content-Type": "application/json",
            "Cookie": self.cookie
        }
        payload = {
            "feature_base64_1": feature1,
            "feature_base64_2": feature2
        }
        response = requests.request("POST", _url, headers=headers, data=json.dumps(payload))
        if response.ok:
            rsp = response.json()
            if rsp.get("rtn") == 0:
                return rsp.get("similarity")
        else:
            return False

# fp = FP()
# ft = fp.get_feature(
#     "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8LCwkMEQ8SEhEPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/2wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh7/wAARCACmAKYDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY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